import { RequestApi } from '@/net/common/API';
import Const from '@/utils/Const';

// 客户列表
export function tenantPage(params: any) {
  let data = Const.dealParamsSwitch(params);
  const apiObj = {
    url: '/bf/sys/tenant/page',
    method: 'post',
    data,
  };
  return new RequestApi().getRequest(apiObj);
}

// 启用、停用
export function tenantChangeStatus(data: any) {
  const apiObj = {
    url: '/bf/sys/tenant/change_status',
    method: 'post',
    data,
  };
  return new RequestApi().getRequest(apiObj);
}

// 新增客户
export function tenantSave(data: any) {
  const apiObj = {
    url: '/bf/sys/tenant/save',
    method: 'post',
    data: {
      ...data,
      url:
        'jdbc:mysql://192.168.17.103:3308/base_frame?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true',
      dbUsername: 'luojl',
      password: 'Kaiya@123',
      driver: 'com.mysql.cj.jdbc.Driver',
    },
  };
  return new RequestApi().getRequest(apiObj);
}

// 编辑客户
export function tenantUpdate(data: any) {
  const apiObj = {
    url: '/bf/sys/tenant/update',
    method: 'post',
    data,
  };
  return new RequestApi().getRequest(apiObj);
}

// 客户详情
export function tenantGetId(id: string) {
  const apiObj = {
    isQuery: true,
    otherUrl: '/bf/sys/tenant/get/*',
    url: `/bf/sys/tenant/get/${id}`,
    method: 'get',
  };
  return new RequestApi().getRequest(apiObj);
}

// 菜单资源树
export function getByScope(idList: any[]) {
  const apiObj = {
    url: '/bf/common/menu/get_by_scope',
    method: 'post',
    data: {
      scope: 0, // 0-不限、1-客户、2-机构、3-角色
      idType: 1, // 0-无、1-客户、2-机构、3-角色
      contain: 2, // 1-只加载授权资源、2-包含已授权和未授权资源
      idList,
    },
  };
  return new RequestApi().getRequest(apiObj);
}

// 获取管理员用户名
export function getEntAdmin(id: string | number) {
  const apiObj = {
    url: '/bf/uc/user/ent_admin',
    method: 'get',
    params: {
      tenant_id: id,
    },
  };
  return new RequestApi().getRequest(apiObj);
}
